package org.a026;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public class T05_ThreadPool {
	@SuppressWarnings("unused")
	public static void main(String[] args) throws InterruptedException, ExecutionException {
		ExecutorService service = Executors.newFixedThreadPool(5);
		
		for(int i=0;i<6;i++){
			Callable<String> tast=new Callable<String>(){

				@Override
				public String call() throws Exception {
					System.out.println("call--");
					return "ss";
				}
				
			};
			Future<String> f = service.submit(tast);
			System.out.println(f.get());
			
			service.execute(()->{
				try {
					TimeUnit.MILLISECONDS.sleep(500);
					if("pool-1-thread-2".equals(Thread.currentThread().getName())) {
						int  n=1/0;
					}
					  
					
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println(Thread.currentThread().getName());
			});
		}
		System.out.println(service);
		service.shutdown();
		System.out.println(service.isTerminated());
		System.out.println(service.isShutdown());
		System.out.println(service);
		try {
			TimeUnit.SECONDS.sleep(5);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println(service.isTerminated());
		System.out.println(service.isShutdown());
		System.out.println(service);
	}
}
